package com.caoyuqi.downloaddemo;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class loadpicture extends Thread{
    static int num = 1;
    private String url;
    private String name;
    public loadpicture(String url,String name)
    {
        this.url = url;
        this.name = name;
    }

    @Override
    public void run() {
        webLoad webLoad = new webLoad();
        webLoad.downloader(url,name);

        System.out.println("下载了名为"+this.name+"的图片");
    }

    public static void main(String[] args) {
        for (int i = 0; i < 9; i++) {
            loadpicture l = new loadpicture("https://img.ivsky.com/img/tupian/t/202103/10/sunyunzhu_wuxiushan_baoshenqun-00"+i+".jpg",num+".jpg");
            num++;
            l.start();
        }

        for (int i = 10; i < 99; i++) {
            loadpicture l = new loadpicture("https://img.ivsky.com/img/tupian/t/202103/10/sunyunzhu_wuxiushan_baoshenqun-0"+i+".jpg",num+".jpg");
            num++;
            l.start();
        }
    }
}

class webLoad
{
    public void downloader(String url,String name)
    {
        try {
            FileUtils.copyURLToFile(new URL(url),new File(name));
        } catch (IOException e) {

            System.out.println("图片下载失败");
        }

    }
}
